[t:/]$ 지식_

초절정 심플 환형 큐

2008/01/23

이건 뭐 새로운 것도 없고 웃기지도 않고. ;; -_-;;

#define QSIZE  2048
unsigned char queue[QSIZE] = { 0 };
int qhead = 0;
int qtail = 0;
int tag  = 0;

void insert_q(unsigned char data)
{
 
 queue[qtail] = data;
 qtail = (qtail + 1) % QSIZE;
 
}
unsigned char get_q()
{
 unsigned char ret;</P>
 ret = queue[qhead];</P>
 queue[qhead] = 0;
 qhead = (qhead + 1) % QSIZE;
 
 return ret;
}

int is_full()  // 큐가 가득 찼냐?
{
 
 if(tag == 1)
  return 1;

 if(qhead == (( qtail + 1) % QSIZE)) {
  tag = 1;
  return 0;
 }
 else
  return 0;

}
int is_empty()  // 큐가 비었냐?
{
 if((qhead == qtail) && (tag == 0)) return 1;</P>
<P> if(qhead == qtail) {
  tag = 0 ;
  return 0;
 }
 else
  return 0;
}




공유하기













[t:/] is not "technology - root". dawnsea, rss